package com.husong.util;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import com.husong.entity.AccountBind;
import com.husong.entity.Conment;
import com.husong.entity.Evaluate;
import com.husong.entity.Order;
import com.husong.entity.OrderBroker;
import com.husong.entity.OrderIndexList;
import com.husong.entity.OrderInfo;
import com.husong.entity.OrderList;
import com.husong.entity.OrderProgress;
import com.husong.entity.OrderWaitList;
import com.husong.entity.Red;
import com.husong.entity.User;
import com.husong.entity.UserWallet;
import com.husong.pojo.AccountBindBean;
import com.husong.pojo.AdvertBean;
import com.husong.pojo.AdvertModel;
import com.husong.pojo.ConmentBean;
import com.husong.pojo.EvaluateBean;
import com.husong.pojo.OrderBean;
import com.husong.pojo.OrderBrokerModel;
import com.husong.pojo.OrderProgressBean;
import com.husong.pojo.RedBean;
import com.husong.pojo.UserBean;
import com.husong.pojo.UserWalletBean;

public class BeanUtil {
	public static Order build(OrderBean bean){
		Order order=new Order();
		order.setAddressId(bean.getAddress_id());
		order.setAdvertId(bean.getAdvert_id());
		order.setBrokerId(bean.getBroker_id());
		order.setCityname(bean.getCityname());
		order.setCreateDate(bean.getCreate_date());
		order.setDesc(bean.getDesc());
		order.setDiscount(bean.getDiscount());
		order.setFee(bean.getFee());
		order.setGetAddressId(bean.getGet_address_id());
		order.setIsdelete(bean.getIsdelete());
		order.setLat(bean.getLat());
		order.setLng(bean.getLng());
		order.setNeedCancel(bean.getNeed_cancel());
		order.setOrderId(bean.getId());
		order.setOrderNo(bean.getOrder_no());
		order.setOrderTypeId(bean.getOrder_type_id());
		order.setSendAddressId(bean.getSend_address_id());
		order.setStatusId(bean.getOrder_status_id());
		
		if(bean.getIsdelete()==1){
			order.setStatusId(0);
		}
		
		order.setTip(bean.getTip());
		order.setToAddressId(bean.getTo_address_id());
		order.setType(bean.getType());
		order.setUpdateDate(bean.getUpdate_date());
		order.setUserId(bean.getUser_id());
		order.setVoicePath(bean.getVoice_path());
		if(bean.getPicpath()!=null&&!"".equals(bean.getPicpath().trim())){
			String[] picpaths = bean.getPicpath().split(",");
			order.setPicpaths(picpaths);
		}
		order.setFromAddress(bean.getFromAddress());
		order.setFromName(bean.getFromName());
		order.setToAddress(bean.getToAddress());
		order.setToName(bean.getToName());
		order.setFromTelephone(bean.getFromTelephone());
		order.setToTelephone(bean.getToTelephone());
		order.setuTelephone(bean.getuTelephone());
		order.setbTelephone(bean.getbTelephone());
		
		order.setuHeader(bean.getuHeader());
		order.setuName(bean.getuName());
		order.setbHeader(bean.getbHeader());
		order.setbName(bean.getbName());
		
		order.setRedAmount(bean.getRedAmount());
		order.setRedDesc(bean.getRedDesc());
		order.setRedType(bean.getRedType());
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		if(bean.getCreate_date()!=null){
			order.setCreateTime(sdf.format(bean.getCreate_date()));
		}
		
		if(bean.getUpdate_date()!=null){
			order.setUpdateTime(sdf.format(bean.getUpdate_date()));
		}
		
		
		return order;
	}
	
	public static OrderInfo buildOrderInfo(OrderBean bean){
		OrderInfo order=new OrderInfo();
		order.setAddressId(bean.getAddress_id());
		order.setAdvertId(bean.getAdvert_id());
		order.setBrokerId(bean.getBroker_id());
		order.setCityname(bean.getCityname());
		order.setDesc(bean.getDesc());
		order.setDiscount(bean.getDiscount());
		order.setFee(bean.getFee());
		order.setLat(bean.getLat());
		order.setLng(bean.getLng());
		order.setNeedCancel(bean.getNeed_cancel());
		order.setOrderId(bean.getId());
		order.setOrderNo(bean.getOrder_no());
		order.setOrderTypeId(bean.getOrder_type_id());
		order.setStatusId(bean.getOrder_status_id());
		
		if(bean.getIsdelete()==1){
			order.setStatusId(0);
		}
		
		order.setTip(bean.getTip());
		order.setToAddressId(bean.getTo_address_id());
		order.setType(bean.getType());
		order.setUserId(bean.getUser_id());
		order.setVoicePath(bean.getVoice_path());
		if(bean.getPicpath()!=null&&!"".equals(bean.getPicpath().trim())){
			String[] picpaths = bean.getPicpath().split(",");
			order.setPicpaths(picpaths);
		}
		order.setFromAddress(bean.getFromAddress());
		order.setFromName(bean.getFromName());
		order.setToAddress(bean.getToAddress());
		order.setToName(bean.getToName());
		order.setFromTelephone(bean.getFromTelephone());
		order.setToTelephone(bean.getToTelephone());
		order.setuTelephone(bean.getuTelephone());
		order.setbTelephone(bean.getbTelephone());
		
		order.setuHeader(bean.getuHeader());
		order.setuName(bean.getuName());
		order.setbHeader(bean.getbHeader());
		order.setbName(bean.getbName());
		
		order.setRedAmount(bean.getRedAmount());
		order.setRedDesc(bean.getRedDesc());
		order.setRedType(bean.getRedType());
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		if(bean.getCreate_date()!=null){
			order.setCreateTime(sdf.format(bean.getCreate_date()));
		}
		
		if(bean.getUpdate_date()!=null){
			order.setUpdateTime(sdf.format(bean.getUpdate_date()));
		}
		
		
		return order;
	}
	public static OrderIndexList buildOrderIndexList(OrderBean bean){
		OrderIndexList order=new OrderIndexList();
		order.setDesc(bean.getDesc());
		order.setOrderId(bean.getId());
		order.setOrderNo(bean.getOrder_no());
		order.setOrderTypeId(bean.getOrder_type_id());
		order.setTip(bean.getTip());
		order.setType(bean.getType());
		order.setUserId(bean.getUser_id());
		order.setVoicePath(bean.getVoice_path());
		if(bean.getPicpath()!=null&&!"".equals(bean.getPicpath().trim())){
			String[] picpaths = bean.getPicpath().split(",");
			order.setPicpaths(picpaths);
		}
		order.setFromAddress(bean.getFromAddress());
		order.setToAddress(bean.getToAddress());
		order.setuHeader(bean.getuHeader());
		order.setuName(bean.getuName());
		
		if(bean.getCreate_date()!=null){
			order.setCreateTime(bean.getCreate_date());
		}
		
		order.seteCount(bean.geteCount());
		order.setzCount(bean.getzCount());
		order.setRow_id(bean.getRow_id());
		
		return order;
	}
	public static OrderWaitList buildOrderWaitList(OrderBean bean){
		OrderWaitList order=new OrderWaitList();
		order.setDesc(bean.getDesc());
		order.setOrderId(bean.getId());
		order.setOrderNo(bean.getOrder_no());
		order.setOrderTypeId(bean.getOrder_type_id());
		order.setTip(bean.getTip());
		order.setType(bean.getType());
		order.setUserId(bean.getUser_id());
		order.setVoicePath(bean.getVoice_path());
		if(bean.getPicpath()!=null&&!"".equals(bean.getPicpath().trim())){
			String[] picpaths = bean.getPicpath().split(",");
			order.setPicpaths(picpaths);
		}
		order.setFromAddress(bean.getFromAddress());
		order.setToAddress(bean.getToAddress());
		order.setuHeader(bean.getuHeader());
		order.setuName(bean.getuName());
		
		if(bean.getCreate_date()!=null){
			order.setCreateTime(bean.getCreate_date());
		}
		
		order.setLat(bean.getLat());
		order.setLng(bean.getLng());
		order.setRow_id(bean.getRow_id());
		return order;
	}
	public static OrderList buildOrderList(OrderBean bean){
		OrderList order=new OrderList();
		order.setDesc(bean.getDesc());
		order.setOrderId(bean.getId());
		order.setOrderNo(bean.getOrder_no());
		order.setOrderTypeId(bean.getOrder_type_id());
		order.setTip(bean.getTip());
		order.setType(bean.getType());
		order.setUserId(bean.getUser_id());
		order.setVoicePath(bean.getVoice_path());
		if(bean.getPicpath()!=null&&!"".equals(bean.getPicpath().trim())){
			String[] picpaths = bean.getPicpath().split(",");
			order.setPicpaths(picpaths);
		}
		order.setFromAddress(bean.getFromAddress());
		order.setToAddress(bean.getToAddress());
		
		order.setuHeader(bean.getuHeader());
		order.setuName(bean.getuName());
		
		if(bean.getCreate_date()!=null){
			order.setCreateTime(bean.getCreate_date());
		}
		
		order.setStatusId(bean.getOrder_status_id());
		if(bean.getIsdelete()==1){
			order.setStatusId(0);
		}
		order.setRow_id(bean.getRow_id());
		order.setFromTelephone(bean.getFromTelephone());
		order.setToTelephone(bean.getToTelephone());
		order.setuTelephone(bean.getuTelephone());
		order.setbTelephone(bean.getbTelephone());
		order.setIsEvaluated(bean.getIsEvaluated());
		return order;
	}
	
	
	public static AdvertModel buildAdvertModel(AdvertBean bean){
		AdvertModel advert=new AdvertModel();
		advert.setAdvertid(bean.getId());
		advert.setCityname(bean.getCityname());
		advert.setDesc(bean.getDescription());
		advert.setPic_path(bean.getPic_path());
		advert.setType(bean.getType());
		advert.setUrl(bean.getUrl());
		return advert;
	}
	
	
	public static UserBean buildUserBean(User user){
		UserBean bean=new UserBean();
		
		bean.setBirthday(user.getBirthday());
		bean.setBrokerStatus(user.getBrokerStatus());
		bean.setCityName(user.getCityName());
		bean.setDeclaration(user.getDeclaration());
		bean.setGender(user.getGender());
		bean.setHeader(user.getHeader());
		bean.setIsauthen(user.getIsauthen());
		bean.setIsbroker(user.getIsbroker());
		bean.setIstested(user.getIstested());
		bean.setIstrained(user.getIstrained());
		bean.setLevel(user.getLevel());
		bean.setNotifyid(user.getNotifyid());
		bean.setPoint(user.getPoint());
		bean.setStars(user.getStars());
		bean.setStatus(user.getStatus());
		bean.setTag(user.getTag());
		bean.setTelephone(user.getTelephone());
		bean.setTitle(PointUtil.convertToTitle(user.getPoint()));
		bean.setUserId(user.getUserId());
		bean.setUsername(user.getUsername());
		
		return bean;
	}
	
	public static UserWallet buildUserWallet(UserWalletBean bean){
		UserWallet wallet=new UserWallet();
		
		wallet.setFrozen_amount(bean.getFrozen_amount());
		wallet.setPurchase_amount(bean.getPurchase_amount());
		wallet.setRecharge_amount(bean.getRecharge_amount());
		wallet.setStatus(bean.getStatus());
		wallet.setTip_amount(bean.getTip_amount());
		
		double purchaseBalance = bean.getPurchase_amount().doubleValue();
		double tipBalance = bean.getTip_amount().doubleValue();
		double total = purchaseBalance;
		if (tipBalance <= 5) {
			total += 0;
		} else if (tipBalance < 50) {
			total += (tipBalance - 5);
		} else {
			total += tipBalance * 0.9;
		}
		wallet.setWithdrawAmount(BigDecimal.valueOf(total));
		return wallet;
	}
	
	
	public static AccountBind buildAccountBind(AccountBindBean bean){
		AccountBind bind=new AccountBind();
		bind.setAccount_no(bean.getAccount_no());
		bind.setAccount_type(bean.getAccount_type());
		bind.setBindid(bean.getId());
		bind.setReal_name(bean.getReal_name());
		bind.setUser_id(bean.getUser_id());
		return bind;		
	}
	
	public static OrderBrokerModel buildOrderBrokerModel(OrderBroker orderBroker){
		OrderBrokerModel model=new OrderBrokerModel();
		model.setDeclaration(orderBroker.getDeclaration());
		model.setDistance(orderBroker.getDistance());
		model.setHeader(orderBroker.getHeader());
		model.setOrderbrokerid(orderBroker.getId());
		model.setPoint(orderBroker.getPoint());
		model.setStars(orderBroker.getStars());
		model.setTitle(PointUtil.convertToTitle(orderBroker.getPoint()));
		model.setUsername(orderBroker.getUsername());
		model.setUser_id(orderBroker.getUser_id());
		return model;
	}
	
	
	public static Evaluate buildEvaluate(EvaluateBean bean){
		Evaluate evaluate=new Evaluate();
		evaluate.setContent(bean.getContent());
		evaluate.setCreate_date(bean.getCreate_date());
		evaluate.setEvaluateid(bean.getId());
		evaluate.setOrderid(bean.getOrderid());
		evaluate.setPoint(bean.getPoint());
		evaluate.setUserid(bean.getUserid());
		evaluate.setRow_id(bean.getRow_id());
		evaluate.setHeader(bean.getHeader());
		evaluate.setUsername(bean.getUsername());
		return evaluate;
	}
	
	public static Conment build(ConmentBean bean){
		Conment conment=new Conment();
		conment.setCommentid(bean.getId());
		conment.setContent(bean.getContent());
		conment.setCreate_date(bean.getCreate_date());
		conment.setHeader(bean.getHeader());
		conment.setOrder_id(bean.getOrder_id());
		conment.setParent_comment_id(bean.getParent_comment_id());
		conment.setParent_username(bean.getParent_username());
		conment.setRow_id(bean.getRow_id());
		conment.setUser_id(bean.getUser_id());
		conment.setUsername(bean.getUsername());
		return conment;
	}
	
	public static OrderProgressBean buildOrderProgress(OrderProgress progress){
		OrderProgressBean bean =new OrderProgressBean();
		bean.setContent(progress.getContent());
		bean.setCreate_date(progress.getCreate_date());
		bean.setOrder_status(progress.getOrder_status());
		bean.setOrderid(progress.getOrderid());
		bean.setProgressid(progress.getId());
		bean.setUser_msg(progress.getUser_msg());
		return bean;
	}
	
	public static RedBean buildRed(Red red){
		RedBean bean=new RedBean();
		bean.setAmount(red.getAmount());
		bean.setCityname(red.getCityname());
		bean.setCreate_date(red.getCreate_date());
		bean.setOrder_id(red.getOrder_id());
		bean.setRed_desc(red.getRed_desc());
		bean.setRed_status(red.getRed_status());
		bean.setRed_type(red.getRed_type());
		bean.setRedid(red.getId());
		bean.setUser_id(red.getUser_id());
		bean.setActive_begin_time(red.getActive_begin_time());
		bean.setActive_end_time(red.getActive_end_time());
		Timestamp time=new Timestamp(System.currentTimeMillis());
		if(time.before(red.getActive_begin_time())){
			bean.setRed_status(4);//活动还未开始
		}
		if(time.after(red.getActive_end_time())){
			bean.setRed_status(3);//过期
		}
		return bean;
	}
}
